package com.scau.database.finalexam.DAO;


import com.scau.database.finalexam.beans.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
public class UsersDao {
    private static Map<String, User> users= null;

    static {
        users = new HashMap<String, User>();
        users.put("1001",new User("1001","zhangsan","123456"));
        users.put("1002",new User("1002","lisi","123456"));
        users.put("1003",new User("1003","xiaoming","123456"));
        users.put("1004",new User("1004","xiaohong","123456"));
        users.put("1005",new User("1005","tiantian","123456"));
    }

    private static Integer initId = 1006;

    public void save(User user){
        if(user.getId() == null){
            user.setId(Integer.toString(initId++));
        }
        users.put(user.getId(), user);
    }

    public User get(String id){
        return users.get(id);
    }
}
